package com.deer.wms.instock.service.enter;

import com.deer.wms.ASN.manage.model.asn.AsnDetail;
import com.deer.wms.ASN.manage.model.asn.AsnMaster;
import com.deer.wms.instock.model.erpType.ErpType;
import com.deer.wms.project.root.core.result.CommonCode;
import com.deer.wms.project.root.exception.ServiceException;
import com.deer.wms.ware.task.model.SO.SoMaster;
import com.deer.wms.ware.task.model.out.OutDetail;
import com.deer.wms.ware.task.model.pushErp.PushErpBean;
import com.deer.wms.ware.task.model.pushErp.beasAssist.BaseAssist;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: xu
 * @Date: 2022/06/17/11:46
 * @Description:
 */
@Component
public class StrategyEnterService implements ApplicationContextAware {
    private Map<ErpType, EnterErp> iFileStrategyMap = new ConcurrentHashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, EnterErp> tmepMap = applicationContext.getBeansOfType(EnterErp.class);
        //根据类型获取
        tmepMap.values().forEach(strategyService -> iFileStrategyMap.put(strategyService.gainType(), strategyService));
    }


    public Map<String,String> resolveAsn(AsnMaster asnMaster, List<AsnDetail> asnDetail, BaseAssist enterAssist) {
        ErpType erpType = new ErpType(asnMaster.getBillType(), asnMaster.getAsnType());
        EnterErp enterErp = iFileStrategyMap.get(erpType);
        if (enterErp != null) {
           return enterErp.EnterBeanAndPush(asnMaster, asnDetail, enterAssist);
        }
        return null;
    }

}
